/*
 * Übung 13.6.2013
 * 1.) Kommandozeilenparameter ausgeben 
 * 2.) wenn s: Server starten
 * 3.) wenn c: Client starten
 * 4.) Parameter über servo.conf einlesen
 *      servo
 *      Port
 *      IP_Addresse
 */
package servointerpreter;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author SchabauerJ
 */
public class ServoInterpreter {

    private static String cmd1;
    private static int port;
    private static String ip;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        // TODO code application logic here

        //Hier wird die servo.conf eingelesen
        Logger logger = Logger.getLogger(ServoInterpreter.class.getName());
        Properties conf = new Properties();
        //String ein= null;
        FileInputStream in = null;
        try {
            in = new FileInputStream("config.properties");
        } catch (FileNotFoundException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
        try {
            conf.load(in);
            in.close();
        } catch (IOException ex) {
            logger.log(Level.SEVERE, null, ex);
        }

        String servo = conf.getProperty("servo");
        String sPort = conf.getProperty("Port");
        port= Integer.parseInt(sPort);
        ip = conf.getProperty("IP-Adresse");
        System.out.println(servo);
        System.out.println(sPort);
        System.out.println(ip);

// Kommandozeilenparameter
        if (args.length == 0) {
            System.out.println("Keine Parameter übergeben");
            System.out.println("\t-c: Client");
            System.out.println("\t-s: Server");
        } else {
            for (String ein : args) {
                System.out.format("%s ", ein);
                cmd1 = ein;
            }
            try {
                if (cmd1.equalsIgnoreCase("-s")) {
                    TCPServer.start(port);
                }
                if (cmd1.equalsIgnoreCase("-c")) {
                    TCPClient.start(ip, port);
                }
            } catch (Exception ex) {
                logger.log(Level.SEVERE, null, ex);
            }
        }
    }
}
